home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: HELP: Illegal Pointer Arithmetic
- Date: Tue, 27 Feb 1996 14:31:04 GMT
- Organization: Netcom
- Message-ID: <31331425.52605482@nntp.ix.netcom.com>
- References: <4gj0ug$730@news.one.net> <danpop.825121139@rscernix> <31306a18.309961701@nntp.ix.netcom.com> <4gq77b$bmo@reznor.larc.nasa.gov> <4gqija$bmo@reznor.larc.nasa.gov>
- NNTP-Posting-Host: ix-dc12-08.ix.netcom.com
- X-NETCOM-Date: Tue Feb 27 6:30:55 AM PST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- hook@cscsun3.larc.nasa.gov (Ed Hook) wrote:
-
- > Following up to myself:
- >
- > In article <4gq77b$bmo@reznor.larc.nasa.gov>, hook@cscsun3.larc.nasa.gov (Ed Hook) writes:
- > |> In article <31306a18.309961701@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
- >
- > [ *deletia* ]
- > |> |>
- > |> |> Not quite that, but Shildt's Annotated ANSI C Standard says
- > |> |>
- > |> |> The following fragment illustrates how files are commonly
- > |> |> read:
- > |> |>
- > |> |> do {
- > |> |> ch = fgetc(fp);
- > |> |> /* ... */
- > |> |> } while (!feof(fp));
- > |> |>
- > |> |> Come on Dan. You're slipping. Surely you could have guessed who
- > |> |> teaches this idiocy.
- > |> |>
- > |> It depresses me to have to defend Schildt, but that loop actually
- > |> works as advertised. (I *do* question his use of "commonly", since
- > |> I have encountered _any_ code that does it that way ... .) Anyhow,
- > |> since 'feof()' is called *after* each iteration of the loopbody,
- > |> the loop terminates precisely after the last character is fetched
- > |> from the file.
- > |>
- > Blair Houghton gently pointed out to me (_via_ e-mail) that the above
- > defense of Schildt is *erroneous*, since the code in question fails on
- > an _empty_ input file. Overall, I feel somehow _cleaner_ now ...
-
- Actually, it fails on every input file since it goes through the loop
- after reaching EOF. An empty file is just one example. On a one
- character file it goes through the loop twice, once with the character
- and once with EOF.
-
- Unless, of course, the unshown code includes a test for ch == EOF, but
- that would be contrary to the concept of an example. feof() returns
- nonzero only after end of file has been reached.
-
-
- Michael M Rubenstein
-